﻿//编辑用户表
EditSys_User = function(id) {
    var EditSys_UserForm = Ext.create("Ext.form.Panel", {
        width: 360,
        height: 450,
       
        layout: "anchor",
        defaultType: "textfield",
        labelWidth: 55,
        baseCls: "x-plain",
        defaults: { labelAlign: 'right', anchor: "90%", msgTarget: "side" },
        buttonAlign: "center",
        bodyStyle: "padding:0 0 0 0",
        items: [{
                       name: "UserID",
            fieldLabel: "<font color='red'>*</font>用户ID号",
            allowBlank: false,
            blankText: "用户ID号不能为空",
            regex: /^[\d]{0,10}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "U_LoginName",
            fieldLabel: "<font color='red'>*</font>登陆名",
            allowBlank: false,
            blankText: "登陆名不能为空",
            regex: /^[\da-zA-Z]{1,20}$/,
            regexText: "请填写1～20个数字或字母"
        }, {
            name: "U_CName",
            fieldLabel: "中文姓名",
            regex: /^[\da-zA-Z]{0,20}$/,
            regexText: "请填写0～20个数字或字母"
        }, {
            name: "U_EName",
            fieldLabel: "英文名",
            regex: /^[\da-zA-Z]{0,9}$/,
            regexText: "请填写0～9个数字或字母"
        }, {
            name: "U_GroupID",
            fieldLabel: "<font color='red'>*</font>所属部门",
            allowBlank: false,
            blankText: "所属部门不能为空",
            regex: /^[\d]{0,10}$/,
            regexText: "请填写0～10个数字"
        }, {
            name: "U_Email",
            fieldLabel: "电子邮件",
            regex: /^[\da-zA-Z]{0,9}$/,
            regexText: "请填写0～9个数字或字母"
        }, {
            name: "U_Type",
            fieldLabel: "用户类型",
            xtype: "combo",
            //传入后台真实值value field /value
            xtype: 'combo',
            editable: false,
            anchor: '90%',
            value: 0,
            store: Ext.create('Ext.data.Store', {
                fields: ['show', 'value'],
                data: [
			        { "show": "是", "value": 1 },
			        { "show": "否", "value":0 }
			    ]
            }),
            queryMode: 'local',
            displayField: 'show',
            valueField: 'value'
        }, {
            name: "U_Status",
            fieldLabel: "当前状态",
            xtype: "combo",
            //传入后台真实值value field /value
            xtype: 'combo',
            editable: false,
            anchor: '90%',
            value: 0,
            store: Ext.create('Ext.data.Store', {
                fields: ['show', 'value'],
                data: [
			        { "show": "是", "value": 1 },
			        { "show": "否", "value":0 }
			    ]
            }),
            queryMode: 'local',
            displayField: 'show',
            valueField: 'value'
        }, {
            name: "U_Licence",
            fieldLabel: "用户序列号",
            regex: /^[\da-zA-Z]{0,9}$/,
            regexText: "请填写0～9个数字或字母"
        }, {
            name: "U_Mac",
            fieldLabel: "锁定机器硬件地址",
            regex: /^[\da-zA-Z]{0,9}$/,
            regexText: "请填写0～9个数字或字母"
        }, {
            name: "U_Remark",
            fieldLabel: "备注说明",
            regex: /^[\da-zA-Z]{0,200}$/,
            regexText: "请填写0～200个数字或字母"
        }, {
            name: "U_IDCard",
            fieldLabel: "身份证号码",
            regex: /^[\da-zA-Z]{0,9}$/,
            regexText: "请填写0～9个数字或字母"
        }, {
            name: "U_Sex",
            fieldLabel: "性别",
            xtype: "combo",
            //传入后台真实值value field /value
            xtype: 'combo',
            editable: false,
            anchor: '90%',
            value: 0,
            store: Ext.create('Ext.data.Store', {
                fields: ['show', 'value'],
                data: [
			        { "show": "是", "value": 1 },
			        { "show": "否", "value":0 }
			    ]
            }),
            queryMode: 'local',
            displayField: 'show',
            valueField: 'value'
        }, {
            xtype:"datefield",
            name: "U_BirthDay",
            fieldLabel: "出生日期",
        }, {
            name: "U_MobileNo",
            fieldLabel: "手机号",
            regex: /^[\da-zA-Z]{0,9}$/,
            regexText: "请填写0～9个数字或字母"
        }, {
            name: "U_UserNO",
            fieldLabel: "员工编号",
            regex: /^[\da-zA-Z]{0,9}$/,
            regexText: "请填写0～9个数字或字母"
        }, {
            xtype:"datefield",
            name: "U_WorkStartDate",
            fieldLabel: "到职日期",
        }, {
            xtype:"datefield",
            name: "U_WorkEndDate",
            fieldLabel: "离职日期",
        }, {
            name: "U_CompanyMail",
            fieldLabel: "公司邮件地址",
            regex: /^[\da-zA-Z]{0,9}$/,
            regexText: "请填写0～9个数字或字母"
        }, {
            name: "U_Title",
            fieldLabel: "职称",
            regex: /^[\d]{1,10}$/,
            regexText: "请填写1～10个数字"
        }, {
            name: "U_Extension",
            fieldLabel: "分机号",
            regex: /^[\da-zA-Z]{0,9}$/,
            regexText: "请填写0～9个数字或字母"
        }, {
            name: "U_HomeTel",
            fieldLabel: "家中电话",
            regex: /^[\da-zA-Z]{0,9}$/,
            regexText: "请填写0～9个数字或字母"
        }, {
            name: "U_PhotoUrl",
            fieldLabel: "用户照片网址",
            regex: /^[\da-zA-Z]{0,255}$/,
            regexText: "请填写0～255个数字或字母"
        }, {
            xtype:"datefield",
            name: "U_DateTime",
            fieldLabel: "操作时间",
        }, {
            name: "U_LastIP",
            fieldLabel: "最后访问IP",
            regex: /^[\da-zA-Z]{0,9}$/,
            regexText: "请填写0～9个数字或字母"
        }, {
            xtype:"datefield",
            name: "U_LastDateTime",
            fieldLabel: "最后访问时间",
        }, {
            name: "U_ExtendField",
            fieldLabel: "扩展字段",
            regex: /^[\w]{0,2147483647}$/,
            regexText: "请填写0～2147483647个数字或字母"
         }
			]
    });

    var EditSys_UserWin = new Ext.Window({
        title: "修改用户表",
        width: 400,
        height: 450,
       
        layout: "fit",
        //iconCls: "addicon",
        //不可以随意改变大小
        resizable: false,
        //是否可以拖动
        //draggable:false,
        defaultType: "textfield",
        //labelWidth: 100,
        collapsible: true, //允许缩放条
        closeAction: 'destroy',
        closable: true,
        //弹出模态窗体
        modal: 'true',
        buttonAlign: "center",
        bodyStyle: "padding:10px 0 0 15px",
        items: [EditSys_UserForm],
        listeners: {
            "show": function() {
                if (id && id != "") {
                    //加载表单数据
                    EditSys_UserForm.form.load(
                                {
                                    url: "/Sys_User/Look/" + id,
                                    method: "get",
                                    success: function(form, action) {

                                    },
                                    failure: function(form, action) {
                                        Ext.Msg.alert("提示信息", "对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
                }
            }
        },
        buttons: [{
            text: "保存信息",
            minWidth: 70,
            handler: function() {
                //alert(EditSys_UserForm.getForm().isValid())
                if (EditSys_UserForm.getForm().isValid()) {
                    //弹出效果 Ext.MessageBox.alert("asdf");
                    Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                    setTimeout(function() { }, 1000);
                    EditSys_UserForm.form.submit({
                        url: "/Sys_User/Update/" + id,
                        method: "POST",
                        success: function(form, action) {
                            //成功后
                             Ext.MessageBox.hide();
                            var flag = action.result.success;
                            if (flag == "true") {
                                Sys_UserStore.loadPage(1);
                               Ext.helper.msg("恭喜", "修改成功!");
                                EditSys_UserWin.hide();
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.MessageBox.alert("修改失败!", message);
                                }
                                else {
                                    Ext.MessageBox.alert("提示!", "修改失败!");
                                    EditSys_UserWin.hide();
                                }

                            }
                        },
                        failure: function(form, action) {
                            Ext.MessageBox.alert("提示!", "修改失败!");
                            EditSys_UserWin.hide();
                        }
                    });
                }
            }
        }, {
            text: "重置",
            minWidth: 70,
            qtip: "重置数据",
            handler: function() {
                //加载表单数据
                EditSys_UserForm.getForm().reset();
                EditSys_UserForm.form.load(
                                {
                                    url: "/Sys_User/Look/" + id,
                                    method: "get",
                                    success: function(form, action) {
                                    },
                                    failure: function(form, action) {
                                        //Ext.Msg.alert("提示信息","对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
            }
        }, {
            text: "取 消",
            minWidth: 70,
            handler: function() {
                EditSys_UserWin.hide();
            }

}]

        });

        EditSys_UserWin.show();
    }
  
